<template>
    <!-- Main content -->
    <div>
        <div class="row">
            <div class="container-fluid">
                <theme-box title="第三方电子券查询">
                    <form class="form-inline" @submit.prevent v-el:form>
                        <form-select title="商户号" :up-table="true" :sreach="true" name="mchtId"
                                     :options="mchtList"></form-select>
                        <form-input title="电子券名称" :up-table="true" name="name" :sreach="true" id="name"></form-input>
                        <form-select title="类型" :sreach="true" :up-table="true" name="type" :options="typeOptions"></form-select>
                        <span class="pull-right">
                            <button type="reset" @click="reset" class="btn btn-warning pull-right">重置</button>
                        <v-button theme="primary" @click="search" class="pull-right">查询</v-button>
                        </span>
                    </form>
                    <table class="table table-bordered table-striped" style="width:100%" v-el:table></table>
                </theme-box>
            </div>
            <!-- /.col -->
        </div>
        <modal-container title="导入" v-el:revise-modal v-ref:revise-modal class="edit-modal" theme="">
            <form @submit.prevent @reset.prevent v-el:revise-mform>
                <div class="import-body edit-body modal-body">
                    <table-modal :item="item" :columns-set="columnsReviseSet" :columns-num="1" v-ref:item></table-modal>
                </div>

                <div class="modal-footer">
                    <v-button data-dismiss="modal" @click="resetBindDrag">关闭</v-button>
                    <v-button theme="primary" type="submit" class="pull-right">保存</v-button>
                </div>
            </form>

        </modal-container>
        <modal-container title="详情" v-el:detail-modal v-ref:detail-modal class="edit-modal">
            <form @submit.prevent @reset.prevent v-el:detail-mform>
                <div class="modal-body">
                    <!-- <table-modal :item="item" :columns-set="columnsDetailSet"></table-modal> -->
                    <table class="table table-bordered table-hover">
                        <tr>
                            <td style="width:50%">商户名称</td>
                            <td>{{item.mchtName}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">电子券号</td>
                            <td>{{item.couponId}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">电子券名称</td>
                            <td>{{item.name}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">适用商户</td>
                            <td>{{item.mchtIds}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">类型</td>
                            <td>
                                {{ (item.type == 'rebate' && '折扣券') || (item.type == 'voucher' && '抵用券') || (item.type == 'cash' && '代金券')|| (item.type == 'present' && '礼品券')|| (item.type == 'ticket' && '门票')}}
                            </td>
                        </tr>
                        <tr v-show="item.restricted != 0">
                            <td style="width:50%">抵用券限制金额</td>
                            <td>{{item.restricted}}</td>
                        </tr>
                        <tr v-show="item.type !='rebate'">
                            <td style="width:50%">面值</td>
                            <td>{{item.denomination}}</td>
                        </tr>
                        <tr v-show="item.type =='rebate'">
                            <td style="width:50%">面值(90代9折)</td>
                            <td>{{item.denomination}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">营销规则</td>
                            <td>{{item.marketRule}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">电子券状态</td>
                            <td>
                                {{(item.type2 == 'default' && '出售、分享、使用') || (item.type2 == 'share' && '分享、使用') || (item.type2 == 'useonly' && '使用')}}
                            </td>
                        </tr>
                        <tr>
                            <td style="width:50%">发券途径</td>
                            <td>
                                {{(item.promAppro == 'general' && '普通券') || (item.promAppro == 'prom' && '推广券') || (item.promAppro == 'reward' && '打赏券') || (item.promAppro == 'buy' && '购买')}}
                            </td>
                        </tr>
                        <tr v-show="item.cash != 0">
                            <td style="width:50%">现金</td>
                            <td>
                                {{(item.cash)}}
                            </td>
                        </tr>
                        <tr>
                            <td style="width:50%">授权商户</td>
                            <td>
                                {{(item.grantMerchant)}}
                            </td>
                        </tr>
                        <tr>
                            <td style="width:50%">总数量</td>
                            <td>{{item.num}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">芸券估值</td>
                            <td>{{item.valuation}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">评估价值</td>
                            <td>{{item.worth}}</td>
                        </tr>
                        <!--<tr>-->
                        <!--<td style="width:50%">人均消费</td>-->
                        <!--<td>{{item.per}}</td>-->
                        <!--</tr>-->
                        <tr>
                            <td style="width:50%">适用范围</td>
                            <td>{{scpoe}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">已授权数量</td>
                            <td>{{issuedNum}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">已出售数量</td>
                            <td>{{item.soldnum}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">剩余数量</td>
                            <td>{{item.surplusnum}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">已使用数量</td>
                            <td>{{item.usednum}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">未使用数量</td>
                            <td>{{item.unusernum}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">状态</td>
                            <td>{{item.status == "0" ? "正常" : "关闭"}}</td>
                        </tr>
                        <tr v-show="item.useRule">
                            <td style="width:50%">使用规则</td>
                            <td>{{useRule}}</td>
                        </tr>
                        <tr v-show="item.useNum">
                            <td style="width:50%">叠加张数</td>
                            <td>{{item.useNum}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">第三方券类型</td>
                            <td>{{item.couponType == 'default'? '默认' : '第三方'}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">第三方描述</td>
                            <td style="word-wrap:break-word;word-break:break-all;">{{item.thirdDesc}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">使用时间段</td>
                            <td>{{item.useTime}}</td>
                        </tr>
                        <tr v-show="item.disableDate">
                            <td style="width:50%">不可用日期</td>
                            <td>{{disableDate}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">有效开始日期</td>
                            <td>{{item.validatyBegin}}</td>
                        </tr>
                        <tr>
                            <td style="width:50%">有效结束日期</td>
                            <td>{{item.validatyEnd}}</td>
                        </tr>
                    </table>
                </div>
                <div class="modal-footer">
                    <v-button class="pull--left" data-dismiss="modal" @click="resetBindDrag">关闭</v-button>
                </div>
            </form>
        </modal-container>
        <map :columns-set="map"></map>
        <!-- /.row -->
    </div>
    <!-- /.content -->
</template>

<style lang="less" scoped>
    .form-inline .btn + .btn {
        margin-right: 10px;
    }

    .form-inline .form-group + .form-group {
        margin-left: 20px;
    }
</style>

<script>
    //解决datatables弹窗警告
    $.fn.dataTable.ext.errMode = 'none';
    import {
        dateTime,
        createDataTable
    } from 'ui/collections/general.js'
    import {dateFormat} from "lib/method.js"
    import {dateTransform} from "lib/method.js"
    var serialize = require('form-serialize');

    var dataTable;
    var columnsSet;
    var columnsAuthorizeSet;
    export default {
        data: () => ({
            eleNum:'',
            over:'',
            repName:'',
            strId:'',
            strNum:'',
            couponType:'',
            promTpe:'',
            scpoe: "",
            issuedNum:"",
            disableDate: "",
            useTime: "",
            useRule: "",
            item: {},
            mchtList: [],
            columnsSet: [],
            columnsReviseSet: [{
                title: "商户名称",
                data: "mchtName",
                edit: true,
                readonly: true,
                className: "operate",
            }, {
                title: "电子券名称",
                data: "name",
                edit: true,
                readonly: true,
                className: "operate"
            },{
                title: "券码",
                data: "file",
                upload:true,
                className:'operate'
            }],
            checkboxOptions: [],
            typeOptions: [
                {key: "所有类型", value: ""},
                {key: "折扣券", value: "rebate"},
                {key: "抵用券", value: "voucher"},
                {key: "代金券", value: "cash"},
                {key: "礼品券",value: "present"},
                {key: "门票",value: "ticket"}
            ],
            disableDay: [
                {key: "星期一", value: "1"},
                {key: "星期二", value: "2"},
                {key: "星期三", value: "3"},
                {key: "星期四", value: "4"},
                {key: "星期五", value: "5"},
                {key: "星期六", value: "6"},
                {key: "星期日", value: "7"},
            ]
        }),
        methods: {
            //还原弹出框位置
            resetBindDrag() {
                this.$refs.modal._resetBindDrag();
            },
            //查询按钮
            search: function () {
                dataTable.ajax.reload();
            },
            //详情按钮
            // details: function() {
            //     dataTable.ajax.reload();
            // },
            //重置按钮
            reset: function () {
                $(".form-inline")[0].reset();
                dataTable.ajax.reload();
            },
            getMcht(data) {
                let self = this;
                var mchtId = JSON.parse(localStorage.getItem("id_token")).mchtId
                self.$post({
                    url: "/api/v2" + projectName_Url + "/list/mcht/" + mchtId,
                    method: "GET"
                }).then(response => {
                    let list = response.content.info;
                    if (list.length == 1) {
                        list.unshift({key: "商户", value: ""});
                        self.$set("mchtList", list);
                    } else {
                        list.unshift({key: "所有商户", value: ""});
                        self.$set("mchtList", list);
                        self.mchtIdValue = list[0].value
                    }
                }, error => {
                });
            }
        },
        created() {
            //主页面datatable所用数组
            columnsSet = [{
                title: "商户号",
                data: "mchtId",
                visible: false,
                className: "operate"
            }, {
                title: "商户名称",
                data: "mchtName",
                edit: true,
                readonly: true,
                className: "operate"
            }, {
                title: "电子券号",
                data: "couponId",
                edit: true,
                readonly: true,
                visible: false,
                className: "operate"
            }, {
                title: "电子券名称",
                data: "name",
                className: "operate"
            }, {
                title: "适用商户",
                data: "mchtIds",
                visible: false,
                className: "operate"
            },  {
                title: "第三方类型",
                data: "couponType",
                className: "operate",
                options: [
                    {key: "默认", value: "default"},
                    {key: "第三方", value: "third"}
                ],
                render: function (data) {
                    var value;
                    if (data == "default") {
                        value = '默认'
                    } else{
                        value = '第三方'
                    }
                    return value;
                }
            }, {
                title: "类型",
                data: "type",
                className: "operate",
                options: [
                    {key: "折扣券", value: "rebate"},
                    {key: "抵用券", value: "voucher"},
                    {key: "代金券", value: "cash"},
                    {key: "礼品券",value: "present"},
                    {key: "门票",value: "ticket"},
                ],
                render: function (data) {
                    var value;
                    if (data == "rebate") {
                        value = '折扣券'
                    } else if (data == "voucher") {
                        value = '抵用券'
                    } else if (data == "cash"){
                        value = "代金券"
                    } else if (data == "present"){
                        value = "礼品券"
                    } else{
                        value = "门票"
                    }
                    return value;
                }
            }, {
                title: "抵用券限制金额",
                data: "restricted",
                edit: false,
                className: "operate"
            }, {
                title: "面值",
                data: "denomination",
                className: "operate"
            }, {
                title: "面值(90代9折)",
                data: "denominationTwo",
                edit: false,
                visible: false,
                className: "operate"
            },{
                title: "营销规则",
                data: "marketRule",
                visible: false,
                className: "operate"
            },
                {
                    title: "电子券状态",
                    data: "type2",
                    className: "operate",
                    options: [
//                    {key: "默认",value: "default"},
                        {key: "分享、使用",value: "share"},
                        {key: "使用",value: "useonly"},
                    ],
                    render: function (data) {
                        var value;
                        if (data == "default") {
                            value = '出售、分享、使用'
                        } else if (data == "share") {
                            value = '分享、使用'
                        } else {
                            value = "使用"
                        }
                        return value;
                    }

                },{
                    title: "总数量",
                    data: "num",
                    className: "operate"
                },{
                    title: "发券途径",
                    data: "promAppro",
                    className: "operate",
                    options: [
                        {key: "普通券", value: "general"},
                        {key: "推广券", value: "prom"},
                        {key: "打赏券", value: "reward"},
                        {key: "购买", value: "buy"},
                    ],
                    render: function (data) {
                        var value;
                        if (data == "general") {
                            value = '普通券'
                        } else if (data == "prom") {
                            value = '推广券'
                        } else if(data == "reward"){
                            value = "打赏券"
                        }else{
                            value = "购买"
                        }
                        return value;
                    }
                },{
                    title: "现金",
                    data: "cash",
                    edit:false,
                    visible: false,
                    className: "operate"
                },{
                    title: "适用范围",
                    visible: false,
                    data: "scpoe",
                    className: "operate",
                    options: [
                        {key: "可用", value: "I"},
                        {key: "不可用", value: "T"}
                    ]
                }, {
                    title: "适用范围选项",
                    visible: false,
                    data: "range",
                    className: "operate",
                }, {
                    title: "已出售数量",
                    visible: false,
                    data: "soldnum",
                    readonly: true,
                    className: "operate"
                }, {
                    title: "剩余数量",
                    visible: false,
                    data: "surplusnum",
                    readonly: true,
                    className: "operate"
                }, {
                    title: "已使用数量",
                    visible: false,
                    data: "usednum",
                    readonly: true,
                    className: "operate"
                }, {
                    title: "未使用数量",
                    visible: false,
                    data: "unusernum",
                    readonly: true,
                    className: "operate"
                },
                {
                    title: "使用规则",
                    visible: false,
                    data: "useRule",
                    className: "operate",
                    checkboxOptions: [{
                        key: "和其他优惠券一起使用",
                        value: "D"
                    }, {
                        key: "叠加使用",
                        value: "M"
                    }]
                }, {
                    title: "叠加张数",
                    visible: false,
                    data: "useNum",
                    edit: false,
                    className: "operate"
                }, {
                    title: "使用开始时间",
                    visible: false,
                    data: "useTime",
                    className: "operate"
                }, {
                    title: "使用结束时间",
                    visible: false,
                    data: "useEndTime",
                    className: "operate"
                }, {
                    title: "使用开始时间2",
                    visible: false,
                    data: "useTime2",
                    className: "operate"
                }, {
                    title: "使用结束时间2",
                    visible: false,
                    data: "useEndTime2",
                    className: "operate"
                }, {
                    title: "不可用日期",
                    data: "disableDate",
                    visible: false,
                    className: "operate",
                    checkboxOptions: [{
                        key: "星期一",
                        value: "1"
                    }, {
                        key: "星期二",
                        value: "2"
                    }, {
                        key: "星期三",
                        value: "3"
                    }, {
                        key: "星期四",
                        value: "4"
                    }, {
                        key: "星期五",
                        value: "5"
                    }, {
                        key: "星期六",
                        value: "6"
                    }, {
                        key: "星期天",
                        value: "7"
                    }]
                }, {
                    title: "有效期开始日期",
                    visible: false,
                    data: "validatyBegin",
                    className: "operate"
                }, {
                    title: "有效期结束日期",
                    visible: false,
                    data: "validatyEnd",
                    className: "operate"
                }, {
                    title: "相关操作",
                    className: "operate",
                    width: "120px",
                    render: function (value, type, row) {
                        return `
                               <button type="button" class="btn btn-primary btn-sm revise">导入</button>
                               <button type="button" class="btn btn-defalt btn-sm detail">详情</button>
                            `
                    }
                }];
        },

        ready: async function () {
            dateTime({
                format: "yyyy-mm-dd",
                minView: "2"
            })
            this.$set("columnsSet", columnsSet);
            var self = this;
            self.getMcht();
            //创建dataTable
            dataTable = $(this.$els.table).DataTable({
                "columns": this.columnsSet, //定义列
                "ajax": async function (data, callback, settings) {
                    var page = [{
                        "name": "iDisplayStart",
                        "value": 1 + data.start / data.length
                    }, {
                        "name": "iDisplayLength",
                        "value": data.length
                    }];
                    //表单序列化数据
                    var _data = serialize(self.$els.form, {
                        hash: true,
                        disabled: true,
                        empty: true
                    });
                    _data.aoData = JSON.stringify(page);
                    //发送请求
                    var mchtId = JSON.parse(localStorage.getItem("id_token")).mchtId;
                    var result = await self.$post({
                        url: "/api/v2" + projectName_Url + "/plat/ImportCouno/query/" + mchtId,
                        data: _data,
                        method: "POST"
                    })
                    if (result.respCode != "00") {
                        Midway.alert({
                            title: "操作失败",
                            content: result.content
                        })
                    }
                    callback({
                        recordsTotal: result.content.total || 0,
                        recordsFiltered: result.content.total || 0,
                        data: result.content.couponList || []
                    })
                    //即将过期的优惠券 有效日期显示红色
                    if (result.content.couponList != '' && result.content.couponList != null) {
                        for (var i in result.content.couponList) {
                            //获取当前时间戳
                            var d= new Date();
                            var d2 = d.getFullYear() + "-"+ (d.getMonth() + 1) +"-"+ d.getDate();
                            //月是一位数时自动补齐0
                            if((d.getMonth() + 1) < 10){
                                var d2 = d.getFullYear() + "-"+ "0"+(d.getMonth() + 1) +"-"+ d.getDate();
                            }
                            //日是一位数时自动补齐0
                            if(d.getDate() < 10){
                                var d2 = d.getFullYear() + "-"+ "0"+(d.getMonth() + 1) +"-"+"0"+d.getDate();
                            }
                            var str = d2.replace(/-/g,'');

                            if(parseInt(result.content.couponList[i].validatyEnd)-parseInt(str) < 0){
                                var trs = $('tbody tr td:nth-child(2)');
                                trs.splice(0,4)
                                $(trs[i]).css('color','red');

                            }
                        }
                    }
                }
            });
            $(self.$el).on("click", ".revise", function () {
                dateTime({
                    format: "yyyy-mm-dd",
                    minView: "2"
                })
                var Row = $(this).closest('tr').get(0);
                const dataArray = JSON.parse(JSON.stringify(dataTable.row(Row).data()));
                self.item = dataArray;
                dateTime()

                //请求提示数量
                self.$post({
                    url: "/api/v2" + projectName_Url + "/plat/ImportCouno/getPrompts",
                    data:{'mchtId':self.item.mchtId,'couponId':self.item.couponId,'num':self.item.num}
                }).then(response => {
                    for(var i = 0;i<response.content.length;i++){
                        //动态生成
                        if(dataArray.file == null){
                            dataArray.file = '未导入'
                        }else{
                            dataArray.file = dataArray.file;
                        }
                        var box = $("<p>文件名称:"+ dataArray.file +"</p><p>导入成功:<span style='color:red'>"+ response.content[i].success +"</span>条</p><p>还可导入:<span style='color:red'>"+ response.content[i].nums +"</span>条</p>");
                        $("p").remove('.import-body tbody tr:nth-child(3) td:nth-child(2) p');
                        $(".import-body tbody tr:nth-child(3) td:nth-child(2)").append(box);
                    }
                });
                //点击关闭 文件名称清空
                $(".modal-footer .btn.btn-default").click(function(){
                    $(".modal-body tbody tr:nth-child(3) td:nth-child(2) input").val('');
                })

                $(".modal-header .close span").click(function(){
                    $(".modal-body tbody tr:nth-child(3) td:nth-child(2) input").val('');
                });
                //编辑框验证、保存、提交
                $(self.$els.reviseMform).validate(self.item.valdate = {
                    async submitHandler() {
                        var form = self.$els.reviseMform;
//                        var _data = serialize(form, {hash: true, disabled: true, empty: true});
                        let formData = new FormData(form);
                        formData.set("mchtId",self.item.mchtId);
                        formData.set("couponId",self.item.couponId);
                        formData.set("num",self.item.num);
                        formData.set("mchtIds",self.item.mchtIds);
                        loading(true)
                        var result = await self.$post({
                            url: "/api/v2" + projectName_Url + "/plat/ImportCouno/importExcel",
                            data: formData,
                            method: "POST"
                        }).then(response => {
                            Midway.alert({title: "操作提示", content: response.errorInfo});
                    }).then(() => loading(false)).catch(() => loading(false));
                        $(".modal-body tbody tr:nth-child(3) td:nth-child(2) input").val('');
                        dataTable.ajax.reload(null, false);
                        $(self.$els.reviseModal).modal('hide');
                        self.resetBindDrag()
                    },
                    rules: {
                        file: {
                            required: true
                        },
                        mchtName: {
                            required: true
                        },
                        name: {
                            required: true
                        }
                    }
                });
                $(self.$els.reviseModal).modal('show');
            });
            $(self.$el).on("click", ".detail", function () {
                var Row = $(this).closest('tr').get(0);
                const dataArray = JSON.parse(JSON.stringify(dataTable.row(Row).data()));
                self.item = dataArray;
                dataArray.validatyBegin = dateTransform(dataArray.validatyBegin);
                dataArray.validatyEnd = dateTransform(dataArray.validatyEnd);
                dateTime()
                //详情弹框里请求已授权数量
                _data = {grantMcht:dataArray.mchtId,couponId:dataArray.couponId};
                self.$post({
                    url: "/api/v2" + projectName_Url + "/plat/grant/getIssuedNum",
                    data:_data,
                    method: "POST"
                }).then(response => {
                    let issuedNum = response.content.issuedNum;
                    self.issuedNum = issuedNum;
                }, error => {
                });
                //详情弹框里请求适用范围选项
                self.$post({
                    url: "/api/v2" + projectName_Url + "/plat/dishType/querylow/" + dataArray.mchtId,
                    method: "GET"
                }).then(response => {
                    let list = response.content.lowTypeNameList;
                    //对适用范围进行数据处理
                    let _arr = self.item.scpoe;
                    dataArray.scpoe = $.trim(_arr[0]);
                    if (dataArray.scpoe == "I") {
                        self.scpoe = "可用:";
                    } else {
                        self.scpoe = "不可用:";
                    }
                    var _newArr = _arr.slice(1, _arr.length + 1);
                    var _rangeArr = _newArr.split(",");
                    var _checkedRange = [];
                    for (var i = 0; i < _rangeArr.length; i++) {
                        for (var k = 0; k < list.length; k++) {
                            if (parseInt(list[k].typeId) == parseInt(_rangeArr[i])) {
                                _checkedRange.push(list[k].typeName);
                            }
                        }
                    }
                    self.scpoe += _checkedRange.join(",") || '无';
                }, error => {
                });
                //详情弹框里适用商户选项
                self.$post({
                    url: "/api/v2" + projectName_Url + "/plat/mcht/getmchtname/" + dataArray.mchtId,
                    method: "GET"
                }).then(response => {
                    let list = response.content.info;
                    //对适用商户进行数据处理
                    let _arr = self.item.mchtIds;
                    var _mchtsArr = _arr.split(",");
                    var _checkedMchts = [];
                    for (var i = 0; i < _mchtsArr.length; i++) {
                        for (var k = 0; k < list.length; k++) {
                            if (parseInt(list[k].mchtId) == parseInt(_mchtsArr[i])) {
                                _checkedMchts.push(list[k].mchtName);
                            }
                        }
                    }
                    self.item.mchtIds = _checkedMchts.join(",") || '无';
                }, error => {
                })

                //详情弹框里营销规则选项
                var _data = {couponType:self.item.type, mchtId:self.item.mchtId};
                self.$post({
                    url: "/api/v2" + projectName_Url + "/plat/rule/list",
                    data:_data,
                    method:"post"
                }).then(response => {
                    let list = response.content.rulesList;
                    let _array = self.item.marketRule;
                    let _ruleArr = _array.split(',')
                    let __checkedRules = [];
                    for (var i = 0; i < _ruleArr.length; i++) {
                        for (var k = 0; k < list.length; k++) {
                            if (parseInt(list[k].value) == parseInt(_ruleArr[i])) {
                                __checkedRules.push(list[k].key);
                            }
                        }
                    }
                    self.item.marketRule = __checkedRules.join(",") || '无';
                }, error => {});

                //详情弹框里授权商户选项
                self.$post({
                    url: "/api/v2" + projectName_Url + "/list/mcht/agent",
                    method: "POST"
                }).then(response => {
                    let list = response.content.list;
                    let _array = self.item.grantMerchant;
                    let _grantArr = _array.split(',')
                    let __checkedGrantMcht = [];
                    for (var i = 0; i < _grantArr.length; i++) {
                        for (var k = 0; k < list.length; k++) {
                            if (parseInt(list[k].key) == parseInt(_grantArr[i])) {
                                __checkedGrantMcht.push(list[k].value);
                            }
                        }
                    }
                    self.item.grantMerchant = __checkedGrantMcht.join(",") || '无';
                });

                //处理使用日期多选数据
                let _myArray = self.item.disableDate.split(",");
                let _myStr = '';
                let set = new Set();
                _myArray.forEach(s => set.add(s));
                if (set.has("1")) {
                    _myStr += "星期一" + " "
                }
                if (set.has("2")) {
                    _myStr += "星期二" + " "
                }
                if (set.has("3")) {
                    _myStr += "星期三" + " "
                }
                if (set.has("4")) {
                    _myStr += "星期四" + " "
                }
                if (set.has("5")) {
                    _myStr += "星期五" + " "
                }
                if (set.has("6")) {
                    _myStr += "星期六" + " "
                }
                if (set.has("7")) {
                    _myStr += "星期日" + " "
                }
                self.disableDate = _myStr;

                //对使用规则进行数据处理
                let _useRule = ["和其他优惠券一起使用", "叠加使用"];
                let _myArr = self.item.useRule.split(",");
                let _str = '';
                let mySet = new Set();
                _myArr.forEach(s => mySet.add(s));
                if (mySet.has("D")) {
                    _str += "和其他优惠券一起使用" + " "
                }
                if (mySet.has("M")) {
                    _str += "叠加使用" + " "
                }
                if (mySet.has("DM")) {
                    _str += "和其他优惠券一起使用," + "叠加使用" + " "
                }
                self.useRule = _str;

                $(self.$els.detailModal).modal('show');
            });
        },
        beforeDestroy() {
            $(this.$el).off("click")
        }
    }
</script>
